#ifndef HTTPHELPER_H
#define HTTPHELPER_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <memory>
#include <QObject>
#include <QVector>
#include <QVariantMap>
#include <map>
//http登录状态
enum REQUESTTYPE
{
    REGISTER = 1,
    LOGIN,
    LOGINOUT,
    MEDIALIST,
    ADDMEDIA,
    EDITMEDIA,
    REMOVEEDIT,
};
//代码格式对齐 ctrl+a，Ctrl+i
class HttpHelper : public QObject
{
    Q_OBJECT
public:
    static HttpHelper* instance();
    ~HttpHelper();
signals:
    //信号是没有返回值
    void sig_Operator(const REQUESTTYPE type,bool result);
    void sig_Mediainfo(const QVector<QVariantMap>madiainfo);
public slots:
    void slot_GetmadiaInfo();
    void slot_Register(const QVariantMap& infomap);
    void slot_Login(const QVariantMap& infomap);
    void slot_LoginOut(const QVariantMap& infomap);
    void slot_AddmediaInfo(const QVariantMap& infomap);
    void slot_EditmediaInfo(const QVariantMap& infomap);
    void slot_RemovemediaInfo(const QVariantMap& infomap);
protected:
    void HandleReply(const QByteArray& data);
    void onReplyFinished(QNetworkReply* reply);
    void sendGetRequest(const QNetworkRequest& request);
    void sendPostRequest(QNetworkRequest&request,const QByteArray& data);
    void sendRequest(const REQUESTTYPE type,bool idPost,const QByteArray data = QByteArray());
private:
    explicit HttpHelper(QObject *parent = nullptr);
    HttpHelper(const HttpHelper&) = delete;
    HttpHelper& operator=(const HttpHelper&) = delete ;
private:
    QString token;
    static std::unique_ptr<HttpHelper> instance_;
    QNetworkAccessManager* networkMannager;
    std::map<REQUESTTYPE,QString> requestAddrs;


signals:

};

#endif // HTTPHELPER_H
